
package edu.tfg.bean;

import edu.tfg.dao.EnderecoDAO;
import edu.tfg.model.Endereco;
import java.util.List;
import java.util.Objects;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Juarez
 */
@ManagedBean
@SessionScoped
public class EnderecoBean {

    public EnderecoBean() {
    }    
    
    private Endereco endereco = new Endereco();
    private EnderecoDAO enderecoDAO = new EnderecoDAO();
    private List listaEndereco;

    public List getListaEndereco() {
        return listaEndereco;
    }

    public void setListaEndereco(List listaEndereco) {
        this.listaEndereco = listaEndereco;
    }

    public Endereco getEndereco() {
        return endereco;
    }

    public void setEndereco(Endereco endereco) {
        this.endereco = endereco;
    }

    public EnderecoDAO getEnderecoDAO() {
        return enderecoDAO;
    }
    

    public void setEnderecoDAO(EnderecoDAO enderecoDAO) {
        this.enderecoDAO = enderecoDAO;
    }
   
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + Objects.hashCode(this.endereco);
        hash = 59 * hash + Objects.hashCode(this.enderecoDAO);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final EnderecoBean other = (EnderecoBean) obj;
        if (!Objects.equals(this.endereco, other.endereco)) {
            return false;
        }
        if (!Objects.equals(this.enderecoDAO, other.enderecoDAO)) {
            return false;
        }
        return true;
    }
    
     public String adicionaEndereco(){
        enderecoDAO.salvar(endereco);
        return "index";
    }

     public String removeEndereco(){
        enderecoDAO.removeEndereco(endereco);
        return "sucesso";
     }
     
      public List listarEndereco(){
         listaEndereco= enderecoDAO.listarEndereco();
         return listaEndereco;
     }
     public String alterarEndereco(){
            enderecoDAO.alterarEndereco(endereco);
         return "index";
     }
     
     public String pesquisarEndereco(){
         enderecoDAO.pesquisarEndereco(null);
         return "index";
     }
    
    
    
}
